/* TweenEntry */
ninejs.extend(ninejs, function( exports ) {
	var TweenEntry = {
		to: function( elem, attr, speed, callback ) {
			var k = 0;

			for ( var i in attr ) {
				if ( attr.hasOwnProperty(i) ) {
					clearInterval(elem["iid_" + k]);
					elem["iid_" + k] = setInterval(function() {
						TweenEntry.start(elem, attr, speed, callback);
					}, 50);
					k++;
				}
			}
		},
		start: function( elem, attr, speed, callback ) {
			var k = 0;

			for ( var i in attr ) {
				if ( attr.hasOwnProperty(i) ) {
					var _val = parseInt(elem.style[i] || exports.getStyle(elem, i)),
						currValue = isNaN(_val) ? 0 : _val,
						direction = (attr[i] - currValue > 0) ? 1 : -1,
						length = Math.abs(attr[i] - currValue);

					if ( length <= speed ) {
						elem.style[i] = (currValue + direction * length) + "px";
						clearInterval(elem["iid_" + k]);
						callback && callback();
					} else {
						elem.style[i] = (currValue + direction * speed) + "px";
					}

					k++;
				}
			}
		},
		setOpacity: function( elem, opacity ) {
			if ( elem.filters ) {
				elem.style.filter = "alpha(opacity=" + opacity + ")";
			} else {
				elem.style.opacity = opacity / 100;
			}
		},
		hide: function( elem ) {
			var display = exports.getStyle(elem, "display");
			if ( display != "none" ) {
				elem._display = display;
			}
			elem.style.display = "none";
		},
		show: function( elem ) {
			elem.style.display = elem._display || "block";
		},
		fadeIn: function( elem, delay, callback ) {
			var _this = this;

			this.setOpacity(elem, 0);
			this.show(elem);

			for ( var i = 0; i <= 100; i += 5 ) {
				(function(j) {
					setTimeout(function() {
						_this.setOpacity(elem, j);
						if ( j == 100 ) {
							callback && callback();
						}
					}, (j + 1) * delay);
				})(i);
			}
		},
		fadeOut: function( elem, delay, isRemove, callback ) {
			var _this = this;

			for ( var i = 0; i < 100; i += 2 ) {
				(function(j) {
					setTimeout(function() {
						_this.setOpacity(elem, 100 - j);
						if ( j == 98 ) {
							if ( !isRemove ) {
								_this.hide(elem);
							} else {
								exports.removeChild(elem);
							}
							callback && callback();
						}
					}, (j + 1) * delay);
				})(i);
			}
		}
	};

	exports.TweenEntry = TweenEntry;
});